package com.jianyun.jyzs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.bean.Bean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by mlli on 2017/12/8.
 */

public class CrmFilterAdapter extends RecyclerView.Adapter {


    private Context context;
    private List<Bean> mDatas = new ArrayList<>();
    private List<Bean> mDatas1 = new ArrayList<>();
    private List<Bean> mDatas2 = new ArrayList<>();


    public CrmFilterAdapter(Context context, List<Bean> list_state, List<Bean> list_instudry) {
        this.context = context;
        mDatas1 = list_state;
        mDatas2 = list_instudry;
        mDatas = mDatas1;
    }

    public void setData(int index){

        if (index==0){
            mDatas = mDatas1;
        }else {
            mDatas = mDatas2;
        }
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.crm_filter_item, parent, false);
        return new MHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MHolder mHolder = (MHolder) holder;
        final Bean bean = mDatas.get(position);
        mHolder.headName.setText(bean.name);
        mHolder.head.setChecked(bean.check);
        mHolder.head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bean.check= !bean.check;
            }
        });
    }
    public List<Bean> getSearchonditionState(){
        return mDatas1;


    }
    public List<Bean> getSearchonditionIndtury(){
        return mDatas2;


    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    class MHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.headName)
        TextView headName;
        @BindView(R.id.head)
        CheckBox head;

        public MHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
